﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BusinessTier;
using DataTier;
using GuiTier.Test;



//Made by Mikkel & Lasse
// Dennis
namespace GuiTier
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void CustomerSearchButtonClick(object sender, EventArgs e)
        {
            //SearchCustomer(CustomerSearchField.Text);
            StatusBar.Text = "Søger..";
            backgroundWorker1.RunWorkerAsync();
            
            


        }


        private void CreateCustomerButtonClick(object sender, EventArgs e)
        {
            //Create customer method
            Customers cus = new Customers();
            Customer tem = new Customer();
            tem.CustomerPhoneNumber = CreateCusPhoneField.Text;
            tem.CustomerName = CreateCusNameField.Text;
            tem.CustomerAddress = CreateCusAddressField.Text;
            tem.CustomerZipCode = CreateCusZipField.Text;
            tem.CustomerEmail = CreateCusEmailField.Text;
            tem.CustomerSex = CreateCusComboBox.Text;
            tem.CustomerBirthday = CreateCusDatePicker.Value;
            tem.CustomerEducation = CreateCusEduField.Text;
            tem.CustomerInterests = CreateCusIntresField.Text;
            cus.AddCustomer(CreateCusPhoneField.Text, CreateCusNameField.Text, CreateCusAddressField.Text, CreateCusZipField.Text, CreateCusEmailField.Text, CreateCusComboBox.Text, CreateCusDatePicker.Value, CreateCusEduField.Text, CreateCusIntresField.Text);
            MessageBox.Show("Kunde oprettet");
            ClearCreateFields();

        }

        private void ClearCustomerButtonClick(object sender, EventArgs e)
        {
            ClearCreateFields();

        }
        private void ClearCreateFields()
        {
            CreateCusPhoneField.Text = "";
            CreateCusNameField.Text = "";
            CreateCusAddressField.Text = "";
            CreateCusZipField.Text = "";
            CreateCusEmailField.Text = "";
            CreateCusEduField.Text = "";
            CreateCusIntresField.Text = "";
            CreateCusDatePicker.Value = DateTime.Now;
        }

        private void CustomerEditButton_Click(object sender, EventArgs e)
        {
            EditCusPhone.ReadOnly = false;
            EditCusName.ReadOnly = false;
            EditCusAddress.ReadOnly = false;
            EditCusZip.ReadOnly = false;
            EditCusEmail.ReadOnly = false;
            EditComboSex.Enabled = true;
            EditCusEdu.ReadOnly = false;
            EditCusBirth.Enabled = true;
            EditCusIntres.ReadOnly = false;
        }

        private void UpdateCusButton_Click(object sender, EventArgs e)
        {
            EditCusPhone.ReadOnly = true;
            EditCusName.ReadOnly = true;
            EditCusAddress.ReadOnly = true;
            EditCusZip.ReadOnly = true;
            EditCusEmail.ReadOnly = true;
            EditComboSex.Enabled = false;
            EditCusEdu.ReadOnly = true;
            EditCusBirth.Enabled = false;
            EditCusIntres.ReadOnly = true;

            // Update customer method

            MessageBox.Show("Kunden blev opdateret!");
        }

        private void S1_Click(object sender, EventArgs e)
        {

            S1.BackgroundImage = Properties.Resources.SeatSelected;


        }

        private void S2_Click(object sender, EventArgs e)
        {
            S2.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S3_Click(object sender, EventArgs e)
        {
            S3.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S4_Click(object sender, EventArgs e)
        {
            S4.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S5_Click(object sender, EventArgs e)
        {
            S5.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S6_Click(object sender, EventArgs e)
        {
            S6.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S7_Click(object sender, EventArgs e)
        {
            S7.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S8_Click(object sender, EventArgs e)
        {
            S8.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S9_Click(object sender, EventArgs e)
        {
            S9.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S10_Click(object sender, EventArgs e)
        {
            S10.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S11_Click(object sender, EventArgs e)
        {
            S11.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S12_Click(object sender, EventArgs e)
        {
            S12.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S13_Click(object sender, EventArgs e)
        {
            S13.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S14_Click(object sender, EventArgs e)
        {
            S14.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S15_Click(object sender, EventArgs e)
        {
            S15.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S16_Click(object sender, EventArgs e)
        {
            S16.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S17_Click(object sender, EventArgs e)
        {
            S17.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S18_Click(object sender, EventArgs e)
        {
            S18.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S19_Click(object sender, EventArgs e)
        {
            S19.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S20_Click(object sender, EventArgs e)
        {
            S20.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S21_Click(object sender, EventArgs e)
        {
            S21.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S22_Click(object sender, EventArgs e)
        {
            S22.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S23_Click(object sender, EventArgs e)
        {
            S23.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S24_Click(object sender, EventArgs e)
        {
            S24.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S25_Click(object sender, EventArgs e)
        {
            S25.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S26_Click(object sender, EventArgs e)
        {
            S26.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S27_Click(object sender, EventArgs e)
        {
            S27.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S28_Click(object sender, EventArgs e)
        {
            S28.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S29_Click(object sender, EventArgs e)
        {
            S29.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S30_Click(object sender, EventArgs e)
        {
            S30.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S31_Click(object sender, EventArgs e)
        {
            S31.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S32_Click(object sender, EventArgs e)
        {
            S32.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S33_Click(object sender, EventArgs e)
        {
            S33.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S34_Click(object sender, EventArgs e)
        {
            S34.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S35_Click(object sender, EventArgs e)
        {
            S35.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S36_Click(object sender, EventArgs e)
        {
            S36.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S37_Click(object sender, EventArgs e)
        {
            S37.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S38_Click(object sender, EventArgs e)
        {
            S38.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S39_Click(object sender, EventArgs e)
        {
            S39.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void S40_Click(object sender, EventArgs e)
        {
            S40.BackgroundImage = Properties.Resources.SeatSelected;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            PictureBox[] pb = new PictureBox[100];
            for (int i = 0; i < Seats.Value; i++)
            {
                pb[i] = new PictureBox();

                pb[i].Location = new System.Drawing.Point(20 * (i + 1) + 20);
                pb[i].Name = "seat" + i;
                pb[i].BackgroundImage = Properties.Resources.Seat;
                pb[i].BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                pb[i].Size = new System.Drawing.Size(20, 20);
                pb[i].TabIndex = 1 + i;
                tabPage2.Controls.Add(pb[i]);
                pb[i].Click += new System.EventHandler(this.SeatClick);
            }

        }
        List<string> SelectedSeatsList = new List<string>();
        private void SeatClick(object sender, System.EventArgs e)
        {

            PictureBox who = (PictureBox)sender;
            if (!SelectedSeatsList.Contains(who.Name))
            {
                who.BackgroundImage = Properties.Resources.SeatSelected;
                SelectedSeatsList.Add(who.Name);
            }
            else
            {
                who.BackgroundImage = Properties.Resources.Seat;
                SelectedSeatsList.Remove(who.Name);
            }

        }

        private void buttonMovieSearch_Click(object sender, EventArgs e)
        {
            var movieController = MovieController.Instance;
            //var listOfFoundMovies = MovieController.Instance.SearchMoviesByTitle(textBoxMovieSearch.Text, checkBoxMovieCurrent.Checked);
            var film = new string[] { "yods", "dsddw", "sdasd", "yods", "dsddw", "sdasd", "yods", "dsddw", "sdasd", "ddd" };
            for (var i = 0; i < 10; i++)
            {
                listViewMovieList.Items.Add(film[i]);
            }

        }


        private void CustomerSearchField_TextChanged(object sender, EventArgs e)
        {

        }

        public void SearchCustomer(string phoneNum)
        {
            Customers cus = new Customers();
            Customer tem = new Customer();
            tem = cus.FindCustomer(phoneNum);
            EditCusPhone.Text = tem.CustomerPhoneNumber;
            EditCusName.Text = tem.CustomerName;
            EditCusAddress.Text = tem.CustomerAddress;
            EditCusZip.Text = tem.CustomerZipCode;
            EditComboSex.Text = tem.CustomerSex;
            EditCusBirth.Value = tem.CustomerBirthday;
            EditCusEdu.Text = tem.CustomerEducation;
            EditCusIntres.Text = tem.CustomerInterests;


        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {

            TestClient test = new TestClient();

            
            
            this.Invoke((MethodInvoker)delegate
            {
                CreateCusNameField.Text = test.echo(CustomerSearchField.Text);
                StatusBar.Text = "Kunde fundet";
            });

            
            
        }

        private void update(string text)
        {

              
            
        }
        
    }
}

